$(document).ready(function(){
	$("#search").keyup(function(){
		find($(this).val(),page,func);
	});
})

function find(data,type,callback){
	$.ajax({
		url: "/admin/fast_search?s="+data+"&type="+type,
		success: function(data){
			$("tr").not("#header").remove();
			$("#pages").remove();
			if (data) {
				request = $.parseJSON(data);
				callback();
				light();
			} else {
				$("table").append("<tr><td colspan='5' align='center' class='gag'>Нет результатов</td></tr>");
			}
		}
	})
}
function add_bank(){
	for (var i = 0; i < request.search.length; i++)
	{
		var str = "<tr><td>"+request.search[i].id+"</td>";
		str += "<td><a href='/"+request.search[i].city+"/banks/"+request.search[i].link+"'>"+request.search[i].name+"</td>";
		str += "<td>"+request.search[i].parent+"</td><td>";
		str += "<a href='/admin/banks/edit/"+request.search[i].id+"'>Редактировать</a>";
		str += " | <a href='/admin/banks/delete/"+request.search[i].id+"'>Удалить</a></td></tr>";
		$("table").append(str);
	}
}
function add_deposit(){
	for (var i = 0; i < request.search.length; i++)
	{
		var str = "<tr><td>"+request.search[i].id+"</td>";
		str += "<td><a href='/"+request.search[i].city+"/deposits/"+request.search[i].id+"'>"+request.search[i].name+"</td><td>";
		str += "<a href='/admin/deposits/edit/"+request.search[i].id+"'>Редактировать</a>";
		str += " | <a href='/admin/deposits/delete/"+request.search[i].id+"'>Удалить</a></td></tr>";
		$("table").append(str);
	}
}
function add_home(){
	for (var i = 0; i < request.search.length; i++)
	{
		var str = "<tr><td>"+request.search[i].id+"</td>";
		str += "<td><a href='/"+request.search[i].city+"/credits/home/"+request.search[i].id+"'>"+request.search[i].name+"</td><td>";
		str += "<a href='/admin/credits/home/edit/"+request.search[i].id+"'>Редактировать</a>";
		str += " | <a href='/admin/credits/home/delete/"+request.search[i].id+"'>Удалить</a></td></tr>";
		$("table").append(str);
	}
}
function add_auto(){
	for (var i = 0; i < request.search.length; i++)
	{
		var str = "<tr><td>"+request.search[i].id+"</td>";
		str += "<td><a href='/"+request.search[i].city+"/credits/auto/"+request.search[i].id+"'>"+request.search[i].name+"</td><td>";
		str += "<a href='/admin/credits/auto/edit/"+request.search[i].id+"'>Редактировать</a>";
		str += " | <a href='/admin/credits/auto/delete/"+request.search[i].id+"'>Удалить</a></td></tr>";
		$("table").append(str);
	}
}
function add_needs(){
	for (var i = 0; i < request.search.length; i++)
	{
		var str = "<tr><td>"+request.search[i].id+"</td>";
		str += "<td><a href='/"+request.search[i].city+"/credits/credit/"+request.search[i].id+"'>"+request.search[i].name+"</td><td>";
		str += "<a href='/admin/credits/needs/edit/"+request.search[i].id+"'>Редактировать</a>";
		str += " | <a href='/admin/credits/needs/delete/"+request.search[i].id+"'>Удалить</a></td></tr>";
		$("table").append(str);
	}
}
function add_carts(){
	for (var i = 0; i < request.search.length; i++)
	{
		var str = "<tr><td>"+request.search[i].id+"</td>";
		str += "<td><a href='/"+request.search[i].city+"/credits/cart/"+request.search[i].id+"'>"+request.search[i].name+"</td><td>";
		str += "<a href='/admin/credits/cart/edit/"+request.search[i].id+"'>Редактировать</a>";
		str += " | <a href='/admin/credits/cart/delete/"+request.search[i].id+"'>Удалить</a></td></tr>";
		$("table").append(str);
	}
}
function add_business(){
	for (var i = 0; i < request.search.length; i++)
	{
		var str = "<tr><td>"+request.search[i].id+"</td>";
		str += "<td><a href='/"+request.search[i].city+"/credits/business/"+request.search[i].id+"'>"+request.search[i].name+"</td><td>";
		str += "<a href='/admin/credits/business/edit/"+request.search[i].id+"'>Редактировать</a>";
		str += " | <a href='/admin/credits/business/delete/"+request.search[i].id+"'>Удалить</a></td></tr>";
		$("table").append(str);
	}
}
function add_vacancy(){
	for (var i = 0; i < request.search.length; i++)
	{
		var str = "<tr><td>"+request.search[i].id+"</td>";
		str += "<td><a href='/"+request.search[i].city+"/banks/vacancies/"+request.search[i].id+"'>"+request.search[i].name+"</td><td>";
		str += "<a href='/admin/vacancies/edit/"+request.search[i].id+"'>Редактировать</a>";
		str += " | <a href='/admin/vacancies/delete/"+request.search[i].id+"'>Удалить</a></td></tr>";
		$("table").append(str);
	}
}
function add_city(){
	for (var i = 0; i < request.search.length; i++)
	{
		var str = "<tr><td>"+request.search[i].id+"</td><td>"+request.search[i].name+"</td><td>";
		str += "<a href='/admin/cities/edit/"+request.search[i].id+"'>Редактировать</a>";
		str += " | <a href='/admin/cities/delete/"+request.search[i].id+"'>Удалить</a></td></tr>";
		$("table").append(str);
	}
}